package com.hangxiang.approval.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hangxiang.approval.common.IntegerCommon;
import com.hangxiang.approval.common.RoleCommon;
import com.hangxiang.approval.common.RoleInsertCommon;
import com.hangxiang.approval.common.RoleUpdateCommon;
import com.hangxiang.approval.dao.RoleDao;
import com.hangxiang.approval.entity.Role;
import com.hangxiang.approval.service.RoleService;
import com.hangxiang.approval.vo.RoleVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;


/**
 * (Role)表服务实现类
 *
 * @author makejava
 * @since 2020-11-23 18:06:44
 */
@Service("roleService")
public class RoleServiceImpl extends ServiceImpl<RoleDao, Role> implements RoleService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private RoleDao roleDao;

    /**
     * 通过ID查询单条数据
     *
     * @param common 主键
     * @return 实例对象
     */
    @Override
    public RoleVo queryByRoleId(RoleCommon common) {
        RoleVo vo = new RoleVo();
        Role role = roleDao.selectByRoleId(common.getRoleId());
        BeanUtils.copyProperties(role, vo);
        return vo;
    }


    /**
     * 新增数据
     *
     * @param roleInsertCommon 实例对象
     * @return 实例对象
     */
    @Override
    public Integer insertRole(RoleInsertCommon roleInsertCommon) {
        Role role = new Role();
        role.setCreateTime(new Date());
        role.setUserId(roleInsertCommon.getUserid());
        roleDao.insert(role);
        return role.getRoleId();
    }

    /**
     * 修改数据
     *
     * @param roleUpdateCommon 实例对象
     * @return 实例对象
     */
    @Override
    public Integer updateRole(RoleUpdateCommon roleUpdateCommon) {
        Role role = new Role();
        BeanUtils.copyProperties(roleUpdateCommon, role);
        roleDao.updateById(role);
        return role.getRoleId();
    }
}